import { Inject, Injectable, UnauthorizedException } from '@nestjs/common';
import { UserService } from '../user/user.service';
import { JwtService } from '@nestjs/jwt';
import BizException from '@libs/common/dto/biz.exception';
import { LoginUserDto } from './dto/login-user.dto';

@Injectable()
export class AuthService {
    @Inject()
    private usersService: UserService

    @Inject()
    private jwtService: JwtService
    constructor() {}
    async login(loginUserDto: LoginUserDto): Promise<any> {
        const user = await this.usersService.findByAccountAndPassword(loginUserDto.account, loginUserDto.password);
        if(user) {
            return this.jwtService.sign(user)
        }else{
            throw new BizException('账户不存在')
        }
    }
}
